<template>
  <div class="">
    <el-dialog title="上传合同" :visible.sync="dialogBoole" width="500px">
      <el-form :model="form" ref="form" label-width="90px" class="demo-form-inline">
        <el-form-item label="合同附件:" prop="contractOss"
                      :rules="{required:true,message:'请上传合同附件',trigger: 'blur',}">
          <image-common v-model="form.contractOss" :limit="5" :disabled="false" :upType="2"/>
        </el-form-item>
        <el-form-item label="说明:" prop="contractRemark">
          <el-input type="textarea" v-model="form.contractRemark" placeholder="请输入说明"
                    :rows="6" maxlength="500" show-word-limit/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleSubmit(1)">取 消</el-button>
        <el-button type="primary" @click="handleSubmit(2)">确 定</el-button>
      </div>


    </el-dialog>
  </div>
</template>

<script>
import * as apis from '@/api/vehicleDisposal/routineHandle.js'

export default {
  name: 'uploadContractDialog',//上传合同
  computed: {},
  watch: {
    'form.contractOss': {
      handler(val) {
        if (val) {
          this.$refs.form.clearValidate('contractOss');
        }
      },
      immediate: true,
      deep: true
    }
  },
  data() {
    return {
      form: {
        contractOss: '',
        contractRemark: '',
        vehicleDisposalId: ''
      },
      dialogBoole: false
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    handleSelect(row) {
      this.$emit('handleSelect', row)
      this.dialogBoole = false
    },

    handleOpen(id) {
      this.dialogBoole = true
      this.form.vehicleDisposalId = id
    },

    handleSubmit(val) {
      if (val === 1) {
        this.form = {
          contractOss: '',
          contractRemark: '',
          vehicleDisposalId: ''
        }
        this.$refs.form.resetFields();
        this.dialogBoole = false

      }

      if (val === 2) {
        this.$refs.form.validate((valid) => {
          if (valid) {
            apis?.uploadContract(this.form).then(res => {
              if (res.code === 200) {
                this.$message.success('上传合同成功')
                this.$emit('successUploadContract')
                this.dialogBoole = false
              }
            })
          }
        });

      }
    }

  },
}
</script>

<style scoped lang="scss">
</style>
